﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InForTheCloud.OAuthLite
{
    public static class EncodingHelper
    {
        const string UNRESERVED = "-._~";
        public static string Encode(this string source)
        {
            StringBuilder result = new StringBuilder();
            foreach (char c in source)
            {
                if (Char.IsDigit(c) || Char.IsLetter(c) || UNRESERVED .IndexOf (c)>=0)
                {
                    result.Append(c);
                    continue;
                }

                result.AppendFormat("%{0:X}", (int) c);
            }
            return result.ToString();
        }
           
    }
}
